package de.ipk_gatersleben.bit.bi.edal.publication;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.border.MatteBorder;

public class AttributeTablePanel extends JPanel {

	private static final long serialVersionUID = 8109825692298261311L;

	static void addComponent(Container cont, GridBagLayout gbl, Component c,
			int x, int y, int width, int height, double weightx,
			double weighty, int ipadx, int ipady) {
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.ipadx = ipadx;
		gbc.ipady = ipady;
		gbc.gridx = x;
		gbc.gridy = y;
		gbc.gridwidth = width;
		gbc.gridheight = height;
		gbc.weightx = weightx;
		gbc.weighty = weighty;
		gbc.insets = new Insets(0, 0, 0, 0);
		gbl.setConstraints(c, gbc);
		cont.add(c);
	}

	public AttributeTablePanel(AttributeLabel label,
			AttributeTextArea textField, int height) {

		this.setBorder(new MatteBorder(0, 0, 1, 0, Color.BLACK));

		GridBagLayout gridBagLayout = new GridBagLayout();

		this.setLayout(gridBagLayout);
		this.setBackground(PropertyLoader.MAIN_BACKGROUND_COLOR);

		JScrollPane scrollableTextPanel = new JScrollPane(textField,
				ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
				ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

		scrollableTextPanel.setPreferredSize(new Dimension(200, height + 5));
		scrollableTextPanel.setBorder(BorderFactory.createEmptyBorder());

		JPanel attributePanel = new JPanel(new BorderLayout());

		attributePanel.add(label, BorderLayout.NORTH);
		attributePanel.setBackground(PropertyLoader.MAIN_BACKGROUND_COLOR);
		attributePanel.setPreferredSize(new Dimension(40, height + 5));

		addComponent(this, gridBagLayout, attributePanel, 0, 0, 1, 1, 0.05, 1,
				50, 10);
		addComponent(this, gridBagLayout, scrollableTextPanel, 1, 0, 1, 1,
				0.95, 1, 50, 10);
	}

}
